<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>mydemo</title>
	<style>
		pre{margin:0;padding:0;}
		div {border:1px solid black;}
		pre {padding:10px;}
		#btn {width:50px;height:20px;}
	</style>
	<script>
	window.onload = function() {
		var i = iResult = 0;
		var oBtn = document.getElementById("btn");
		oBtn.onclick = function() {
			this.innerHTML = sum(1,2,3)
		}

		function sum() {
			for (var i=0;i<arguments.length;i++) {
				iResult += arguments[i];
			}
			return iResult;
		}
	}
	</script>
</head>
<body>
<div>
<pre>
&lt;script type="text/javascript">
    var i = iResult = 0;
    function sum()
    {
       for (var i = 0; i < arguments.length; i++)
       {
          iResult += arguments[i];
       }
        return iResult;
    }
    //应用
    alert(sum(1,2,3,4,5,6,7,8,9,10));  //输出55
&lt;/script>
</pre>
<button id="btn">结果</button>
	</div>
</body>
</html>